/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var article = {};
var common = require('../../utils/commonUtils');
//db转换成model
article.dbConvertModel = function(db){
	var article = {}; 
	if(common.isNotBlank(db.id)) article.id = db.id;	
	if(common.isNotBlank(db.member_id)) article.memberId = db.member_id;	
	if(typeof db.member_name != "undefined") article.memberName = db.member_name;
	if(typeof db.member_img_url != "undefined") article.memberImgUrl = db.member_img_url;
	if(typeof db.title != "undefined") article.title = db.title;
	if(typeof db.img_url != "undefined") article.imgUrl = db.img_url;
	if(typeof db.content != "undefined") article.content = db.content;
	if(common.isNotBlank(db.type)) article.type = db.type;	
	if(common.isNotBlank(db.comment_num)) article.commentNum = db.comment_num;	
	if(common.isNotBlank(db.collect_num)) article.collectNum = db.collect_num;	
	if(common.isNotBlank(db.like_num)) article.likeNum = db.like_num;	
	if(common.isNotBlank(db.create_time)){
		article.createTime = db.create_time;
		article.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		article.updateTime = db.update_time;
		article.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) article.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) article.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) article.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") article.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") article.bak5 = db.bak5;
	return article;
};

//model转换成db
article.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(common.isNotBlank(obj.memberId)) db.member_id = obj.memberId;
	if(typeof obj.memberName != "undefined") db.member_name = obj.memberName;
	if(typeof obj.memberImgUrl != "undefined") db.member_img_url = obj.memberImgUrl;
	if(typeof obj.title != "undefined") db.title = obj.title;
	if(typeof obj.imgUrl != "undefined") db.img_url = obj.imgUrl;
	if(typeof obj.content != "undefined") db.content = obj.content;
	if(common.isNotBlank(obj.type)) db.type = obj.type;
	if(common.isNotBlank(obj.commentNum)) db.comment_num = obj.commentNum;
	if(common.isNotBlank(obj.collectNum)) db.collect_num = obj.collectNum;
	if(common.isNotBlank(obj.likeNum)) db.like_num = obj.likeNum;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

article.initPostReq = function(req){
	var article = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (article.id = req.body.id) : (article.id = req.body.id.trim());
	}
	if(req.body.memberId != undefined){
		(typeof req.body.memberId != 'string') ? (article.memberId = req.body.memberId) : (article.memberId = req.body.memberId.trim());
	}
	if(req.body.memberName != undefined){
		(typeof req.body.memberName != 'string') ? (article.memberName = req.body.memberName) : (article.memberName = req.body.memberName.trim());
	}
	if(req.body.memberImgUrl != undefined){
		(typeof req.body.memberImgUrl != 'string') ? (article.memberImgUrl = req.body.memberImgUrl) : (article.memberImgUrl = req.body.memberImgUrl.trim());
	}
	if(req.body.title != undefined){
		(typeof req.body.title != 'string') ? (article.title = req.body.title) : (article.title = req.body.title.trim());
	}
	if(req.body.imgUrl != undefined){
		(typeof req.body.imgUrl != 'string') ? (article.imgUrl = req.body.imgUrl) : (article.imgUrl = req.body.imgUrl.trim());
	}
	if(req.body.content != undefined){
		(typeof req.body.content != 'string') ? (article.content = req.body.content) : (article.content = req.body.content.trim());
	}
	if(req.body.type != undefined){
		(typeof req.body.type != 'string') ? (article.type = req.body.type) : (article.type = req.body.type.trim());
	}
	if(req.body.commentNum != undefined){
		(typeof req.body.commentNum != 'string') ? (article.commentNum = req.body.commentNum) : (article.commentNum = req.body.commentNum.trim());
	}
	if(req.body.collectNum != undefined){
		(typeof req.body.collectNum != 'string') ? (article.collectNum = req.body.collectNum) : (article.collectNum = req.body.collectNum.trim());
	}
	if(req.body.likeNum != undefined){
		(typeof req.body.likeNum != 'string') ? (article.likeNum = req.body.likeNum) : (article.likeNum = req.body.likeNum.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (article.createTime = req.body.createTime) : (article.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (article.updateTime = req.body.updateTime) : (article.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (article.bak1 = req.body.bak1) : (article.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (article.bak2 = req.body.bak2) : (article.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (article.bak3 = req.body.bak3) : (article.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (article.bak4 = req.body.bak4) : (article.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (article.bak5 = req.body.bak5) : (article.bak5 = req.body.bak5.trim());
	}
	return article;
};

article.initGetReq = function(req){
	var article = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (article.id = req.query.id) : (article.id = req.query.id.trim());
	}
	if(req.query.memberId != undefined){	
		(typeof req.query.memberId != 'string') ? (article.memberId = req.query.memberId) : (article.memberId = req.query.memberId.trim());
	}
	if(req.query.memberName != undefined){	
		(typeof req.query.memberName != 'string') ? (article.memberName = req.query.memberName) : (article.memberName = req.query.memberName.trim());
	}
	if(req.query.memberImgUrl != undefined){	
		(typeof req.query.memberImgUrl != 'string') ? (article.memberImgUrl = req.query.memberImgUrl) : (article.memberImgUrl = req.query.memberImgUrl.trim());
	}
	if(req.query.title != undefined){	
		(typeof req.query.title != 'string') ? (article.title = req.query.title) : (article.title = req.query.title.trim());
	}
	if(req.query.imgUrl != undefined){	
		(typeof req.query.imgUrl != 'string') ? (article.imgUrl = req.query.imgUrl) : (article.imgUrl = req.query.imgUrl.trim());
	}
	if(req.query.content != undefined){	
		(typeof req.query.content != 'string') ? (article.content = req.query.content) : (article.content = req.query.content.trim());
	}
	if(req.query.type != undefined){	
		(typeof req.query.type != 'string') ? (article.type = req.query.type) : (article.type = req.query.type.trim());
	}
	if(req.query.commentNum != undefined){	
		(typeof req.query.commentNum != 'string') ? (article.commentNum = req.query.commentNum) : (article.commentNum = req.query.commentNum.trim());
	}
	if(req.query.collectNum != undefined){	
		(typeof req.query.collectNum != 'string') ? (article.collectNum = req.query.collectNum) : (article.collectNum = req.query.collectNum.trim());
	}
	if(req.query.likeNum != undefined){	
		(typeof req.query.likeNum != 'string') ? (article.likeNum = req.query.likeNum) : (article.likeNum = req.query.likeNum.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (article.createTime = req.query.createTime) : (article.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (article.updateTime = req.query.updateTime) : (article.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (article.bak1 = req.query.bak1) : (article.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (article.bak2 = req.query.bak2) : (article.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (article.bak3 = req.query.bak3) : (article.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (article.bak4 = req.query.bak4) : (article.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (article.bak5 = req.query.bak5) : (article.bak5 = req.query.bak5.trim());
	}
	return article;
};


module.exports = article;
